% Preamble
\documentclass[11pt]{article}
\usepackage{graphicx}    % needed for including graphics e.g. EPS, PS
\topmargin -1.5cm        % read Lamport p.163
\oddsidemargin -0.04cm   % read Lamport p.163
\evensidemargin -0.04cm  % same as oddsidemargin but for left-hand pages
\textwidth 16.59cm
\textheight 21.94cm 
%\pagestyle{empty}       % Uncomment if don't want page numbers
\parskip 7.2pt           % sets spacing between paragraphs
\renewcommand{\baselinestretch}{1.5} % Uncomment for 1.5 spacing between lines
\parindent 0pt		
%\usepackage{setspace}
%\usepackage{graphicx}
%\doublespacing
%\linespread{1.5}

\title{Improving molecular clouds grain surface chemistry model.}
\author{Pavel Senin}
\date{\today}

% Document
\begin{document}
% create title page and toc
\maketitle
\clearpage
\tableofcontents
\clearpage

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% start text here!!
\begin{abstract}
Data acquisition and processing in Astronomy and Astrophysics often rely on the use of the IDL software package. While being exceptionally handy and powerful in the data processing and filtering along with small scale applications, it became difficult when building large programs due to the single namespace and array processing constraints. Taking as starting point the IDL coded software that were facing design limitation I want to present current effort of software re-factoring using Java along with outlining the perspectives of project extension. I would show the new model design with improved model configurability and extended functionality. It was found that that while the choice of Java over the original IDL implementation imposes visible performance impact the new flexible modular structure allows easier code and dataflow understanding along with ability to scale over multi processor architecture, which allows system to overcome performance issue.
\end{abstract}

\section{Introduction}
Despite the space between stars in our galaxy appears to be completely empty of matter, there exists a
very dilute gas and grain particles even in "empty" space. This interstellar medium varies in density and composition. Typical densities in the interstellar medium are one particle per cubic centimeter, but there are some regions known as molecular clouds where densities are 10,000 times greater than average. These are dark clouds of gas where it is cold enough for hydrogen to exist mostly in the form of molecules. In addition to gas interstellar dust grains composed of clumps of atoms and molecules. These grains are microscopic, about $10^{-5}$ cm across. Interstellar dust grains are even less common in space than atoms or molecules of gas, there is 1 dust grain for every 1 trillion gas particles. However, considering the vast volume of observed clouds
in space, the total number of dust particles within can be considerable. 

Interstellar cloud is generic name given to a conglomeration of gas, plasma and dust in galaxies. In other words, an interstellar cloud is a denser-than-average region of the interstellar medium. Among others, clouds are classified depending on their density, size and temperature, the hydrogen in it can be neutral (H I regions), ionized (H II regions) (ie. a plasma), or molecular (molecular clouds). Neutral and ionized clouds are called diffuse clouds, while molecular clouds are also referred to as dense clouds. 

The evolution of the star that emerged from the raw interstellar medium could be predicted in very impressive details by contemporary science, as for the actual star formation process it is poorly understood. It is extremely challenging problem for both observational and theoretical grounds and fully detailed star-formation storyline has not yet been written. But it happens to be crucial component for the complete picture of the History of Universe. Star formation itself starts the process of planetary formation, and the feedback between actively forming stars and their large-scale surroundings, through stellar winds and supernovae, affects the formation and evolution of an entire galaxy. It happens to be very difficult to make progress in any of these fields without a precise model of star formation.

The molecular clouds were discovered our own Milky Way Galaxy in the mid 1960's by astronomers using radio telescopes tuned to the millimeter wavelengths at which many kinds of molecules in space emit radiation. Typical molecular cloud in the Milky Way may contain up to several million solar masses in cold gas and spans over the space about tens of parsecs across. The average temperatures within these clouds are normally 10 - 20 degrees above absolute zero and the gas is mostly in the form of hydrogen molecules, with trace amounts of more easily detected material such as carbon monoxide (CO). The millimeter-wavelength emission of CO molecules allows us to map and study these clouds. The new tools for observing at infrared and millimeter wavelengths that began to be developed over the last 20 years have revolutionized the observations of star forming regions. Infrared light from young stars and heated dust, as well as the millimeter and submillimeter radiation from gas molecules, can propagate full picture of these dense dusty realms. 

	Interstellar ices observed toward young stellar objects embedded in molecular clouds show a varied composition with distinct water rich and inert components containing a variety of carbon-bearing species, including $CO$, $CO_{2}$, $H_{2}CO$, $CH_{3}OH$, and $CH_{4}$. 
	
	It should be noted, that during evolution of young protostars, the surroundings become heated and small saturated species are liberated from the mantles, either by evaporation or shocks, into the gas phase. Influenced by various mantle compositions, strong chemical variations between different sources are observed in the gas-phase (i.e., nitrogen-bearing species or oxygen-bearing organic species). These "foreign" grain surface chemistry species injected into the warm gas will be converted back to CO and other typical gas phase species. In the process of conversion, complex molecules are made; some of which may have prebiotic significance (Ehrenfreund \& Charnley 2000; Snyder 1997). Comets, agglomerates of the icy and rocky debris with left over from the planetary forming process, also change chemical signatures of the natal molecular cloud.

\subsection{Previous work}
	In the early studies interstellar chemistry was clearly divided by two grounds: gas-phase chemistry and surface chemistry and the role of surface phase itself were often ignored: it was believed that grains play a passive role in interstellar chemistry by acting simply as reservoirs of molecules that previously condensed out from the gas phase. A well known exception was $H_{2}$, which had been shown to be formed exclusively on grains (Hollenbach \& Salpeter 1971). However, it is now generally accepted that a substantial fraction of the cataloged gas phase species can not in fact be exclusively formed through gas phase chemistry or that their abundances are considerably greater than what a gas phase origin can account for.

	This work takes as the basis for construction original model and computational software designed by J. Keane and A. G. G. M. Tielens, [1] presented during Computational Astrobiology Summer School at August 2006. There were two issues with the software evolution: first was the need of software improvements to fit latest changes in the model and second was making software available for public domain through "scientific portals".

	While the first problem could be solved by very little changes in the original code the overall cost of IDL platform that starts from $\$3000$ for base single-user package eliminates second goal completely. After preliminary analysis of the model background and its IDL implementation the choice of Object-Oriented platform was natural, Java was chosen due to the cross-platform compatibility.

	To meet second goal, availability for public domain, the Google-Code site was selected as the SVN host for the process of development. The software available for download from \mbox{http://code.google.com/p/iclouds}  along with source-codes, Javadocs, and Manual.

	This paper will proceed from outlying the underlying theoretical base of the model along with proposed system design to the preliminary results obtained during Fall 2006 ICS 699 work. Overall performance analysis of Java based model against IDL based model would be spotted along with  new features already incorporated into the existed model as the proof of concept.

\section{Design.}

\subsection{The chemical model.}
The model adopted a "scoundrel approach" (Charnley et al. 1992) and consider that chemical reactions occurring on the grain surface are solely responsible for the formation of the molecular species investigated here. The model follows the Monte Carlo, accretion limited method of Tielens \& Hagen (1982), which is based upon two essential and simplifying assumptions:
\begin{itemize}
	\item the accretion timescale $\textgreater\textgreater$ the timescales for reaction of the accreted atom $H$, $N$, $C$, or $O$, with other species;
	\item there is no desorption of grain mantle species and thus the surface chemistry is not coupled back to the gas-phase.
\end{itemize}

The reactions considered here are presumed to occur only between weakly bound sites (i.e. from one physisorbed to another physisorbed site).


\subsection {Accretion}
The constituents of the gas are limited to the species that dominate the bulk composition of the gas, i.e., $H$, $C$, $CO$, $O$, $O_{2}$, $N$, and $N_{2}$. A gas-phase species $i$ accretes on to the grain at a rate:
\[
R_{acc} \left(i\right)=n_{i} \overline{v}\left(i\right)\pi a^{2}
\]
where where $n_i$ and $\overline{v}\left(i\right)$ are the gas-phase abundance relative to hydrogen and the mean velocity of the species $i$, and a is the grain size. Thermal velocities of the gas phase species are given by: 
\[
\overline{v}\left(i\right) = \sqrt{\frac{3kT_g}{m_i}}
\]
where $m_i$ is the mass of the gas species $i$, $T_g$ is the temperature of the gas (10K) and $k$ is the Boltzmann constant. It is assumed that the sticking coefficient (i.e. the probability that a species stays on the surface after the collision) is unity for all species striking the grain surface. Accretion
is a random process with a probability given by:
\[
P_{acc}\left(i\right) = \frac{R_{acc}\left(i\right)}{\sum _{j} R_{acc} \left(j\right)}
\]
where the summation is over all gas phase species. The accretion timescale, $\tau_{acc}$, is then given by:
\[
\tau_{acc}^{-1} = \sum _{j} R_{acc} \left(j\right)
\]
For a 1000 \AA grain, $\tau_{acc} \approx 10^{5}$ at $n=10^{4}cm^{-3}$ and $T=10K$.

\subsection {Surface mobility and chemistry}
Model assumes that all species are physisorbed rather than chemisorbed on the ice surfaces. The mobility of an accreted species, i.e. the ability to diffuse from one physisorbed site to another, is crucial to the likelihood of a reaction occurring on the grain surface. Theoretical studies of H diffusion on ice surfaces show that quantum mechanical tunneling dominates the diffusion process at 10K with a diffusion timescale which varies between between $10^{-12}s$ and $10^{-9}s$ depending on the assumptions (Hollenbach $\&$ Salpeter 1971; Leitch-Devlin $\&$ Williams 1984; Tielens $\&$ Allamandola 1987). Atoms heavier than ${H}$ (${N}$, ${C}$, and ${O}$) are presumed to diffuse through thermal hopping:
	\[
	\tau^{-1}_{hop} = v_{0} \exp\left[-\frac{E_{dif}}{kT_{d}}\right]
\]
where $T_{d}$ is the dust temperature (10K) and $E_{dif}$ represents the barrier that must be overcome in order for the species to diffuse from one site to another. $v_{0}$ is the characteristic vibrational frequency (i.e., represented as an harmonic oscillator) of the grain surface species, and a value of $10^{12}s^{-1}$ is have chosen to use. $E_{dif} \approx 0.3E_{b}=240K$, where $E_{b}$ denotes the binding energy of the species to the grain surface, which is typically 800K for atoms on an icy grain surface (Tielens \& Hagen 1982). This leads to a thermal hopping timescale of $\approx10^{-2}s$ for these atoms. The time it takes a diffusing species to visit
all sites on the grain surface (i.e. scan the surface) is: 
\[
\tau_{scan} = N_{\tau}
\]
where depending on the diffusing species $\tau$ is either $\tau_{tun}$ or or $\tau_{hop}$. For a 1000 \AA~ grain, $N \approx 10^{6}$ and $\tau_{scan}$ is then $\leq$ $10^{-3}$ for atomic H and $10^{4}s$ for $C$, $N$, and $O$. Both of these are less than the accretion timescale.We note that heavier atoms, radicals or molecules are more strongly bound to an icy surface (Tielens \& Allamandola 1987) and hence, on an accretion timescale, such species are immobile.

The process of roaming the grain surface is essentially that of a random walk. An accreted species will remain
on the grain surface for a time equal to time it takes the species to thermally desorb (evaporation timescale):
\[
\tau_{evap} = v^{-1}_{0} exp \left[\frac{E_{b}}{kT_{d}}\right] 
\]
where relevant binding energies are given by Tielens \& Allamandola (1987). The desorption timescale of atomic
$H$ is then $\approx 10^{-3}s$, i.e. much less than the accretion timescale but larger than $\tau_{scan}$. For atomic $C$, $N$, and $O$ as well as all other species the evaporation timescale is long compared to all other relevant timescales (at 10K). A mobile $H$ atom can visit each reacting site then at most:
\[
\eta = \tau_{evap}/\tau_{scan}
\]
which for the parameters above is $\approx 10^{6}$. Of course, if the atom reacts rapidly, $\eta$ may be much less. For the other atoms, the relevant timescale to consider is the accretion timescale, and $\eta$ is then 10.

Model assumes that species with unpaired electrons react upon "collision" on a grain surface. Reaction of atoms with molecules having paired electrons may also occur upon collision depending on kinetic considerations (Tielens \& Hagen 1982). The probability for an $H$ atom $(i)$ to react with a non-radical species $(j)$ depends on the barrier against reaction (activation barrier, $E_{a_{j}}$ ):
\[
P_{i,j} = \tau v_{0} \exp\left[-\frac{2a}{\hbar}\sqrt{2mE_{a_{j}}}\right]
\]
where $\tau$ represents the time spent in a site (in this case $\tau_{tun}$). If the reactant is not an $H$ atom (i.e. either $N$, $C$, or $O$) then the term in the exponent is replaced by the likelihood of thermally hopping over the activation barrier $(E_{a}/kT_{d})$. The probability of an atom reacting within one evaporation timescale ($\tau_{evap}$) is then given by:
\[
\phi_{i,j} = \theta_{j}kP_{i,j}
\]
where $\theta_{j}$ is the surface concentration of the co-reactant and $k$ is the number of times the atom enters a specific site before it either reacts or evaporates. We note that the diffusion timescale drops out, and thus the reaction probability in each visit is independent of the exact rate at which a species diffuses across the surface. A faster diffusion timescale limits, of course, the reaction probability but that is exactly counteracted by the increase in the collision rate. The potential of a reaction occurring is then determined by the rate of
finding a coreactant:
\[
\phi_{i,j} = \theta_{j}
\]
where $\tau_{i}$ is either due to tunneling or to thermal hopping, depending on the nature of the diffusing species. The key point is that a reaction will occur within an evaporation timescale for $H$ (which is also at the base of the modified rate approach of Caselli et al. (1998)).

The overall reaction probability of species $i$ with species $j$ must then be weighted by all the reactions that
are possible for species $i$:
\[
R_{i,j} = \phi_{i,j}/\sum_{l=1}^{n}\phi_{i,l}
\]
where the summation is over all reactions possible. Now, within this competition of surface species for a newly accreted $H$, when there is another radical on the surface, atomic $H$ will react with this radical even if the surface is otherwise completely covered $(\theta=1)$ with reaction partners with $E_{a}$ as low as 450K. On the other hand, if there is no radical "waiting on" the surface, $H$ will "select" among
the coreactants according to the activation barrier and
the surface concentration of the coreactants involved. We
stress once more that the reaction probability (Eq. 11) is
independent of the diffusive timescale and the total reaction
time (e.g., the exact value of k)

\subsection{Software model design}
	As already mentioned in introduction, early analysis showed that process described above is naturally fits object-oriented design paradigm. Among all available object-oriented languages Java was a natural choice due to the cross-platform compatibility and such Java options as Collections Framework and Javadocs.
\begin{figure*}
\centerline{
\mbox{\includegraphics[width=5.00in]{cloud_object.eps}}
}
\caption{The software model.}
\label{classes}
\end{figure*} 
 For the current implementation there were created classes for the physical properties and constants, atoms, molecules and grain surface along with cloud container for them (Figure 1.). The data processing methods relies on the use of Sampler Interface that has only Uniform implementation so far. Internal data structures and loops employ Collection Framework. 

 The particular cloud model configured by the XML file that contains all of the physical properties along with initial cloud population and chemistry network. The configuration file then parsed by software and resulted in instantiation of the main Cloud class that will evolve in time according to the chemistry network. The Cloud class itself encapsulates current state of cloud at any given time: 
\begin{itemize}
  \item cloud physical properties: temperature, density, etc...
	\item the gas phase population: atoms and molecules which encapsulated their physical properties;
	\item the grain(s) with its predefined chemistry network and physical properties such as size and chemical composition.
	\item predefined by configuration accretion process with selected distribution for sampling, sampling models and others constraints.
	\item predefined by configuration evaporation process (not designed yet).
\end{itemize}

\begin{figure*}
\centerline{
\mbox{\includegraphics[width=4.00in]{data_flow.eps}}
}
\caption{Data flow.}
\label{classes}
\end{figure*} 

Having such a modular design where all system components driven by configuration file allow user do not touch the software programming part and concentrate effort on the configuring the model. In the same time decoupling of components exceptionally useful when the computation model change required. It is fairly easy to touch only the unit that should be changed without going into surroundings. 

	Moreover it is clearly seen that system could be scaled to have multiple grains with varied chemistry networks. I believe that employing such an option along with usage of parallel computing could lead to the overall model improvement along with shortening time of test runs.

\section{Results}
I want to point coincidence of two facts that helped a lot in the project evolution. While doing the work over this project I was taking ICS613 class by Dr. Johnson and was immediately introducing all best software-engineering practices along the way. From the beginning of refactoring effort all of the source code was available at SVN repository at $http://code.google.com/p/iclouds$. While this not only provides sources to the community, this allows me to communicate easily with authors of the original model fixing bugs and discussing overall data and computation flow. I believe that this software would be available for the community and after this project closure. The complete javadocs and automatic system testing routines are would be extremely helpful for any developer joining the project with any level of competence. The software itself is coded in Eclipse, but I have provided Ant scripts for IDE independent building of the system. Finalizing adding stuff learned in software-engineering class I am planning to add nice GUI system configurator for setting-up experiments.


phase Each software in its lifecycle faces refactoring phase with intention to enhance it in unforeseen ways and to overall improve its quality and maintainability by improving its documentation, modularity, performance, as well as other quality attributes. Here I present results of refactoring effort this effort was Coupling object-oriented nature of Java along with recent improvements in Java Collection framework and release of IDL Connector Objects for Java can alleviate these difficulties. In this proposal I report the progress done during this Fall ICS 699 course along with outlining aims for the Spring ICS 700 work. I would show how new model design allowed us to improve model configurability and extend model functionality through very little coding effort. I found that while the choice of Java over the original IDL implementation imposes minimal visible performance impact in single-threaded implementation many desirable properties and flexibilities makes it more attractive for the users and it could be scaled easily in multi-processor hardware to gain performance. I believe that this effort result augur well for the use of Java in the scientific computational modeling.

\clearpage

 and described in the article "Modeling grain surface chemistry in dense molecular clouds"
\begin{thebibliography}{1}

\bibitem{Kato99}
J.~Keane and A.~G.~G.~M.~Tielens \emph{Modeling grain surface chemistry in dense molecular clouds}.\hskip 1em plus
  0.5em minus 0.4em\relax ???, USA.

\end{thebibliography} 

\end{document}
